home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada,comp.lang.c++
- Path: in2.uu.net!world!bobduff
- From: bobduff@world.std.com (Robert A Duff)
- Subject: Re: some questions re. Ada/GNAT from a C++/GCC user
- Message-ID: <Dp75DK.DMG@world.std.com>
- Organization: The World Public Access UNIX, Brookline, MA
- References: <wnewmanDoxrCp.DKv@netcom.com> <Dp1oAw.7Cz@world.std.com> <4jlj79$h1k@Nntp1.mcs.net>
- Date: Mon, 1 Apr 1996 18:44:08 GMT
-
- In article <4jlj79$h1k@Nntp1.mcs.net>, Mike Young <mikey@mcs.com> wrote:
- >I'd been bemoaning the lack of iostreams in Ada. Would you elaborate (no pun
- >intended) more on how "&" and 'Image would be used?
-
- Well, I'm not sure exactly what you're asking. To print stuff out, you
- need some procedure that prints text strings, and you need some way to
- convert whatever you want to print out into a text string. In Ada,
- 'Image is used to convert simple data types like Integer and Float into
- human-readable Strings. For complicated data types, you write your own
- Image function. The "&" operator just concatenates Strings. So to
- print out some stuff, you write:
-
- Put("X = " & Integer'Image(X) & "; and List = " & Image(List));
-
- Where List is a variable of some complicated data structure. This
- converts X and List to type String, concatenates the whole mess
- together, and prints it to standard output.
-
- Does that answer your question?
-
- >Yup. Good practice is not limited by choice of language, I see. :)
-
- :-)
-
- >The other sad part of function-like macros is safety of side-effects in macro
- >arguments. ...
-
- Indeed.
-
- >In spite of this, macros are still the only way to perform some useful tasks.
- >For example:
- >
- >#ifndef _DEBUG
- >#define assert(a)
- >#else
- >#define assert(a) {if (!a) {_assert_fail(__FILE__, __LINE__, #a);}}
- >#endif
- >
- >How would you do this in Ada?
-
- I don't know of any way to do that in Ada. However, that's not a huge
- problem. You indicate a run-time error by raising an exception. You
- can write an Assert procedure that checks the condition, and raises an
- exception if False. Any reasonable debugger can tell you what line of
- code failed, and show you the line of code. And any reasonable debugger
- can tell the difference between an exception that is handled, with
- intent to continue executing, and an exception that is unhandled, and is
- therefore just a bug.
-
- - Bob
-